import 'package:flutter/material.dart';
import 'package:mahjong/entity/MessageContext.dart';
import 'package:mahjong/notify/CurrentUserInfo.dart';
import 'package:mahjong/page/mahjong/dialog/GameDissolution.dart';
import 'package:mahjong/util/CustomNavigatorObserver.dart';
import 'package:mahjong/entity/mahjong/DissolutionEntity.dart';
import 'package:provider/provider.dart';
import 'AbstractMessageHandler.dart';
import 'package:mahjong/util/ConstState.dart';

class MessageDissolution extends AbstractMessageHandler {
  void doMessage(MessageContext message) {
    var userProvider = Provider.of<CurrentUserInfo>(
        CustomNavigatorObserver.getContext(),
        listen: false);
    DissolutionEntity entityInfo = DissolutionEntity.fromJson(message.body);
    Provider.of<DissolutionEntity>(
            CustomNavigatorObserver.getContext(),
            listen: false)
        .update(entityInfo);
    if (!ConstState.getInstance().dissolutionShow) {
      showDialog<Null>(
          context: CustomNavigatorObserver.getContext(),
          barrierDismissible: false,
          builder: (BuildContext context) {
            return GameDissolution(
              dissolutionEntity: entityInfo,
              currentUserId: userProvider.sysUser.username,
            );
          });
    }
  }
}
